package kr.co.goodwilldd.framework.util;

import java.io.File;
import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;

public class FileUtil {

	// TODO Spring Security Dependency 
	//@Autowired
	//ShaPasswordEncoder shaPasswordEncoder;
	
	public String doRename(String fileName) {
		//return shaPasswordEncoder.encodePassword(fileName, System.currentTimeMillis()+getRandom());
		return fileName;
	}
	
	private int getRandom() {
		return (int)(Math.random()*100);
	}
	
	public String doMakeUploadFolder() {
		String root = "";
		Calendar cal = Calendar.getInstance();
		try {
			if (getOS().toLowerCase().indexOf("window") < 0) {
				root = "/";
			} else {
				root = "c:" + File.separator;
			}
			root += "publicMeshData" + File.separator;
			root += cal.get(Calendar.YEAR) + File.separator
					+ (cal.get(Calendar.MONTH) + 1) + File.separator
					+ cal.get(Calendar.DATE) + File.separator;
			File folder = new File(root);
			if (!folder.exists())
				folder.mkdirs();
		} catch (Exception e) {
		}
		return root;
	}

	private String getOS() {
		return System.getProperty("os.name");
	}
}
